package com.yifan.clone;

import java.io.*;

/**
 * @Author YIFan
 * @Date 2020/7/15 14:13
 * @Version 1.0
 */
public class Person implements Serializable {

    private Integer age;
    private String name;
    private  Arm arm;

    public void setArm(Arm arm) {
        this.arm = arm;
    }

    public Arm getArm() {
        return arm;
    }

    /*
     * 深度克隆
     *
     * */

    public Object deepClone() throws IOException, ClassNotFoundException {
        // 将对象写到流里
        ByteArrayOutputStream stream = new ByteArrayOutputStream();
        ObjectOutputStream outputStream = new ObjectOutputStream(stream);
        outputStream.writeObject(this);

        // 从流里读出来
        ByteArrayInputStream inputStream = new ByteArrayInputStream(stream.toByteArray());
        ObjectInputStream iStream1 = new ObjectInputStream(inputStream);
        return iStream1.readObject();
    }


    public Person(Integer age, String name) {
        this.age = age;
        this.name = name;
    }

    public void setAge(Integer age) {
        this.age = age;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Integer getAge() {
        return age;
    }

    public String getName() {
        return name;
    }
}
